import { Action, ElMessageBox } from "element-plus";
import { ComponentStyleType } from "../../type";
import { PopupOptions } from "../type";

export interface MessageBoxOptions extends PopupOptions, ComponentStyleType {}

class MessageBox {
	/**
	 * 弹出层配置项
	 * @param options
	 */
	open(options: MessageBoxOptions) {
		ElMessageBox.alert(options.content as string, options.title, {
			confirmButtonText: options.confirmText || "确定",
			cancelButtonText: options.cancelText || "取消",
			showCancelButton: true,
			callback: (action: Action) => {
				if (action == "confirm") {
					options.confirm && options.confirm(options.content as string);
				} else {
					options.cancel && options.cancel(options.content as string);
				}
			},
		});
	}
}

const messageBox = new MessageBox();
export { messageBox };
